//
//  HomeDataTool.m
//  Traveling
//
//  Created by 尹桥印 on 15/6/4.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "HomeDataTool.h"

@implementation HomeDataTool


+(void)getTravelineWithMaxId:(NSInteger)maxId success:(void (^)(TravelineRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@line/list.json",BASE_URL] param:param resultClass:[TravelineRes class] success:success failure:failure];
}

+(void)getScenicoWithMaxId:(NSInteger)maxId searchKey:(NSString *)searchKey success:(void (^)(ScenicoRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:searchKey forKey:@"search_key"];
    
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@scenic/list.json",BASE_URL] param:param resultClass:[TravelineRes class] success:success failure:failure];
}

+(void)getSpecialtyWithMaxId:(NSInteger)maxId success:(void (^)(TraveSpecialtyRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@food/list.json",BASE_URL] param:param resultClass:[TraveSpecialtyRes class] success:success failure:failure];
}

+(void)getHotelWithMaxId:(NSInteger)maxId success:(void (^)(HotelStayRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@hotel/hotel_list.json",BASE_URL] param:param resultClass:[HotelStayRes class] success:success failure:failure];
}

+ (void)getHotelRoomListWithContentId:(NSInteger)contentId success:(void (^)(HotelRoomRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:[NSNumber numberWithInteger:contentId] forKey:@"content_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@hotel/room_list.json",BASE_URL] param:param resultClass:[HotelRoomRes class] success:success failure:failure];
}

+ (void)getLocationListWithContentId:(NSInteger)contentId success:(void (^)(LocationListRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:[NSNumber numberWithInteger:contentId] forKey:@"content_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@scenic/locationslist.json",BASE_URL] param:param resultClass:[LocationListRes class] success:success failure:failure];
}

+ (void)getHomeAdvList:(void (^)(BannerRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/adv/list.json",BASE_URL] param:param resultClass:[BannerRes class] success:success failure:failure];
}

+ (void)getPlaneResultWithParams:(NSDictionary *)params success:(void (^)(PlaneResultInfo *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:params];
    [param setObject:@"b4cc31cc37909dea0cc8be1c6d37d069" forKey:@"key"];
    [self getWithUrl:@"http://apis.juhe.cn/plan/bc" param:param resultClass:[PlaneResultInfo class] success:success failure:failure];
}


+ (void)getTrainListWithStartCity:(NSString *)startCity endCity:(NSString *)endCity targetTime:(NSString *)targetTime success:(void (^)(TrainResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:kAppValue forKey:kAppkey];
    [param setObject:startCity forKey:@"start_city"];
    [param setObject:endCity forKey:@"end_city"];
    [param setObject:targetTime forKey:@"target_time"];
    [self getWithUrl:[NSString stringWithFormat:@"%@api/train_tickts/list.json",BASE_URL] param:param resultClass:[TrainResponse class] success:success failure:failure];
}

@end
